<?php

namespace App\Http\Middleware;

use Closure;
use DB;

class AdminLoginMiddleware
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        if(session('uid')){
            $res = DB::table('shop_users')->where('uid',session('uid'))->value('auth');
            if($res == 1){
                return $next($request);
            }else{
                return redirect('/admin/login/index')->with('error','未获取权限');
            }
        }else{
            return redirect('/admin/login/index')->with('error','您还没有登录');
        }
        
    }
}
